{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "# 1 基本使用方法\n",
    "\n",
    "启动Python/Ipython Shell有几种方式：\n",
    "\n",
    "* 命令行窗口键入python并回车\n",
    "* 切换到你喜欢的目录，键入ipython notebook并回车\n",
    "* 终端中键入Ipython并回车，或者在IDE中打开一个IPython"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "每次键入命令需要摁下Enter键（REPL中）或者Run Cell按钮（IPython）\n",
    "\n",
    "你会得到一个显示结果反馈。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "42"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "8 * 5 + 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "世间真理42，以及"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1267650600228229401496703205376L"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 ** 100"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "超大整数，或者试试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'The answer to life,the universe,and everything is ?'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"The answer to life,the universe,and everything is ?\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "字符串。\n",
    "\n",
    "用print打印任意我们想要的内容：\n",
    "\n",
    "（一个对象在REPL中直接回车和被print分别输出的是他的\\_\\_repr\\_\\_和\\_\\_str\\_\\_方法对应的字符串）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Scala|Python|C\n",
      "42\n",
      "42 42\n"
     ]
    }
   ],
   "source": [
    "print \"Scala|Python|C\"\n",
    "print 42\n",
    "print repr(42),str(42)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "但是如果需要用户在电脑上输入一些字符怎么办？反复输入和打印字符串也并不方便。\n",
    "\n",
    "####Keep your code DRY (Don't Repeat Yourself)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Scala|Python|C\n"
     ]
    }
   ],
   "source": [
    "lang = \"Scala|Python|C\"\n",
    "print lang"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果需要标识注释，请以# 符号开始一段语句（这与大部分脚本语言和unix-shell语言一样）。从# 开始直到一行结束的内容都是注释。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "These lines can be run.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'\\nWhatever.\\n'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Skip these comments.\n",
    "print \"These lines can be run.\"\n",
    "print '''\n",
    "Whatever.\n",
    "'''"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#2 Python变量入门\n",
    "\n",
    "\n",
    "### 2.0 Python变量的一些概念\n",
    "\n",
    "* 赋值时创建变量本身，绑定名字\n",
    "\n",
    "* 动态类型\n",
    "\n",
    "* 强类型\n",
    "\n",
    "* 可变类型与不可变类型\n",
    "\n",
    "### 2.1 Python变量介绍\n",
    "\n",
    "通常用等号（=）用来给变量赋值。等号（=）运算符左边是一个变量名,等号（=）运算符右边是存储在变量中的值或者一个复合的表达式。\n",
    "\n",
    "试试在python shell里键入以下内容，每打一行摁下Enter键："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<type 'int'>\n",
      "4298149336\n",
      "5292\n",
      "<type 'str'>\n",
      "4352948184\n",
      "Hello,world!Hello,world!\n",
      "Hello,world!Hello,world!\n",
      "Help on built-in function id in module __builtin__:\n",
      "\n",
      "id(...)\n",
      "    id(object) -> integer\n",
      "    \n",
      "    Return the identity of an object.  This is guaranteed to be unique among\n",
      "    simultaneously existing objects.  (Hint: it's the object's memory address.)\n",
      "\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "a = 42\n",
    "b = 42*3\n",
    "print type(a)\n",
    "print id(b)\n",
    "print a*b\n",
    "b = \"Hello,world!\"\n",
    "print type(b)\n",
    "print id(b)\n",
    "print b * 2\n",
    "print b + b\n",
    "help(id)\n",
    "#print dir(a),'\\n'*2,dir(b)\n",
    "print isinstance(a,int)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "###2.2 Python变量赋值与操作\n",
    "\n",
    "多变量赋值（不推荐）："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42 42 42\n"
     ]
    }
   ],
   "source": [
    "x = y = z = 42\n",
    "print x,y,z"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当然你也可以为多个对象指定多个变量，例如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "So long and thanks for all the fish\n"
     ]
    }
   ],
   "source": [
    "x,y,z = \"So long\",\"and thanks for all\",\"the fish\"\n",
    "print x,y,z"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "####赋值的语法糖（Syntax Sugar）："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42\n",
      "So long\n"
     ]
    }
   ],
   "source": [
    "x,y = \"So long\",42\n",
    "x,y = y,x\n",
    "print x\n",
    "print y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Python同样拥有增量赋值方法："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "43\n",
      "84\n"
     ]
    }
   ],
   "source": [
    "a = 42\n",
    "a += 1\n",
    "print a\n",
    "a -= 1\n",
    "a *= 2\n",
    "print a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "类似的能够赋值的操作符还有很多，包括：\n",
    "\n",
    "* \\*= 自乘\n",
    "* /= 自除\n",
    "* %= 自取模\n",
    "* \\*\\*= 自乘方\n",
    "* <<= 自左移位\n",
    "* \\>\\>= 自右移位\n",
    "* &= 自按位与\n",
    "* ^= 自按位异或\n",
    "\n",
    "等等。\n",
    "\n",
    "注意：Python不支持x++ 或者 --x  这类操作。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "### 2.3 Python数值类型\n",
    "\n",
    "* int:     42  126 -680  -0x92\n",
    "* bool:    True False\n",
    "* float:   3.1415926 -90.00 6.022e23 \n",
    "* complex: 6.23+1.5j -1.23-875j 0+1j\n",
    "\n",
    "* type: 判断类型\n",
    "* isinstance: 判断属于特定类型（推荐）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<type 'int'> <type 'bool'> <type 'float'> <type 'complex'>\n",
      "True True True False\n",
      "6.23\n",
      "1.5\n"
     ]
    }
   ],
   "source": [
    "a,b,c,d = 42,True,3.1415926,6.23+1.5j\n",
    "print type(a),type(b),type(c),type(d)\n",
    "print isinstance(a,int),isinstance(b,(float,int)),\\\n",
    "    isinstance(c,float),isinstance(d,(int,bool))\n",
    "\n",
    "# 可以分别取得复数的实部和虚部\n",
    "print d.real\n",
    "print d.imag"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "####工业级的计算器：\n",
    "\n",
    "基础操作符：\n",
    "\n",
    "\\+ \\- \\*  /  // % \\*\\*\n",
    "\n",
    "比较操作符：\n",
    "\n",
    "< <= > >= == !="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(6.23+2.5j) (6.23+0.5j) (-1.5+6.23j)\n",
      "21 49\n",
      "2 3.33333333333 3.33333333333 3\n",
      "False True\n",
      "1\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "d = 6.23+1.5j\n",
    "e = 0+1j\n",
    "print d+e,d-e,d*e\n",
    "\n",
    "print 7*3,7**2  # x**y 返回x的y次幂\n",
    "\n",
    "print 8%3,float(10)/3,10.0/3,10//3\n",
    "\n",
    "print 1==2, 1 != 2    #==表示判断是否相等   != 表示不相等\n",
    "print 7%2           #返回除法的余数\n",
    "\n",
    "print 1<42<100"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "####是时候展现真正的除法了："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "1.75\n"
     ]
    }
   ],
   "source": [
    "print 7/4\n",
    "from __future__ import division\n",
    "print 7/4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "普通floor除法："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "print 7//4 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "布尔值："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n",
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "print not True\n",
    "print not False\n",
    "print 40 < 42 <= 100\n",
    "print not 40 > 30\n",
    "print 40 > 30 and 40 < 42 <= 100   \n",
    "print 40 < 30  or 40 < 42 <=100"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###2.4 Python字符串类型\n",
    "\n",
    "字符串的长度len与切片："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11\n",
      "H el\n",
      "d Hello world\n",
      "Hlowrd dlrow olleH\n"
     ]
    }
   ],
   "source": [
    "c = \"Hello world\"\n",
    "print len(c)\n",
    "print c[0],c[1:3]\n",
    "print c[-1],c[:]\n",
    "print c[::2],c[::-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "复杂切片操作：[start:end:step]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dlrow olleH\n",
      "Hello world\n",
      "Hlowrd\n",
      "Hello wo\n",
      "Hlow\n"
     ]
    }
   ],
   "source": [
    "c = \"Hello world\"\n",
    "print c[::-1]   #翻转字符串\n",
    "print c[:]      #原样复制字符串\n",
    "print c[::2]    #隔一个取一个\n",
    "print c[:8]     #前八个字母\n",
    "print c[:8:2]   #前八个字母，每两个取一个"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "复制："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello world\n",
      "Hell\n",
      "4369762608\n",
      "4369762608\n",
      "4369762608 Hell\n"
     ]
    }
   ],
   "source": [
    "c = \"Hello world\"\n",
    "d = c[:]        #复制字符串，赋值给d\n",
    "del c           #删除原字符串\n",
    "print d         #d 字符串依然可用\n",
    "e = d[0:4]\n",
    "print e         #新构造一个截取d字符串部分所组成的串\n",
    "f = e\n",
    "print id(f)\n",
    "print id(e)\n",
    "del e\n",
    "print id(f),f        #仍然可用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "加号（+）用于字符串连接运算，星号（*）用来重复字符串。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------\n",
      "Clojure iscool\n",
      "Clojure isClojure isClojure is\n",
      "--------------------\n"
     ]
    }
   ],
   "source": [
    "teststr,stringback=\"Clojure is\",\"cool\"\n",
    "print '-'*20\n",
    "print teststr+stringback\n",
    "print teststr*3\n",
    "print '-'*20"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "美化打印："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------\n",
      "Clojure is cool\n",
      "--------------------\n",
      "Clojure is\tcool\n",
      "--------------------\n"
     ]
    }
   ],
   "source": [
    "pystr,pystring=\"Clojure is\",\"cool\"\n",
    "print '-'*20\n",
    "print pystr,pystring\n",
    "print '-'*20\n",
    "print pystr+'\\t'+pystring\n",
    "print '-'*20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python's Format I : Clojure is cool\n",
      "Python's Format II: Scala is awesome\n",
      "C Style Print: LISP is wonderful \n"
     ]
    }
   ],
   "source": [
    "pystr = \"Clojure\"\n",
    "pystring = \"cool\"\n",
    "yastr = \"LISP\"\n",
    "yastring = \"wonderful \"\n",
    "print('Python\\'s Format I : {0} is {1}'.format(pystr,pystring))\n",
    "print 'Python\\'s Format II: {language} is {description}'.\\\n",
    "format(language='Scala',description='awesome') #使用\\接续换行\n",
    "print 'C Style Print: %s is %s'%(yastr,yastring)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "字符串复杂效果举例："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                        *\n",
      "                                      ******\n",
      "                                   ***********\n",
      "                                 ****************\n",
      "                              *********************\n",
      "                                   ***********\n",
      "                                 ****************\n",
      "                              *********************\n",
      "                            **************************\n",
      "                         *******************************\n",
      "                       ************************************\n",
      "                                 ****************\n",
      "                              *********************\n",
      "                            **************************\n",
      "                         *******************************\n",
      "                       ************************************\n",
      "                    *****************************************\n",
      "                  **********************************************\n",
      "               ***************************************************\n",
      "             ********************************************************\n",
      "                                   ***********\n",
      "                                   ***********\n"
     ]
    }
   ],
   "source": [
    "for i in range(0,5)+range(2,8)+range(3,12)+[2,2]:\n",
    "    print' '*(40-2*i-i//2)+'*'*(4*i+1+i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "尾部换行\\："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"A:What's your favorite language?B:C++.\""
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"A:What's your favorite language?\\\n",
    "B:C++.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\t：水平制表符："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A:What’s your favorite language?\n",
      "B:C++\n",
      "A:What’s your favorite language?\tB:C++\n"
     ]
    }
   ],
   "source": [
    "print \"A:What’s your favorite language?\\nB:C++\"\n",
    "print \"A:What’s your favorite language?\\tB:C++\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "注意其他的转义字符（反斜线＋字符）："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What's your favorite language?\n",
      "What's your favorite language?\n",
      "What\"s your favorite language?\\\n"
     ]
    }
   ],
   "source": [
    "print 'What\\'s your favorite language?'\n",
    "print \"What's your favorite language?\"\n",
    "print \"What\\\"s your favorite language?\\\\\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "其他操作 —— Join，Split，Strip, Upper, Lower"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\tb\tc\td\n",
      "['a', 'b', 'c', 'd']\n",
      "a,b,c,d\n",
      "Blabla\n",
      "Blabla \t \n",
      "\n",
      "\t Blabla\n",
      "ABCDEFG\n",
      "abcdefg\n"
     ]
    }
   ],
   "source": [
    "s = \"a\\tb\\tc\\td\"\n",
    "print s\n",
    "l = s.split('\\t')\n",
    "print l\n",
    "snew = ','.join(l)\n",
    "print snew\n",
    "line = '\\t Blabla \\t \\n'\n",
    "print line.strip()\n",
    "print line.lstrip()\n",
    "print line.rstrip()\n",
    "salpha = 'Abcdefg'\n",
    "print salpha.upper()\n",
    "print salpha.lower()\n",
    "\n",
    "#isupper islower isdigit isalpha"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "更多操作：\n",
    "\n",
    "* 查阅dir('s')\n",
    "* 查阅codecs\n",
    "* 查阅re（regexp，正则表达式）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###2.5 初识Python可变类型（Mutables）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 字符串（string）：不可变\n",
    "* 字节数组（bytearray）：可变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<type 'str'>\n"
     ]
    }
   ],
   "source": [
    "s = \"string\"\n",
    "print type(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'str' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-14-70c1b7211999>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ms\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"o\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "s[3] = \"o\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Strong\n"
     ]
    }
   ],
   "source": [
    "s = \"String\"\n",
    "sba = bytearray(s)\n",
    "sba[3] = \"o\"\n",
    "print sba"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
